package com.corner.presenter.imp;

import com.corner.model.cornerservice.domain.User;
import com.corner.model.cornerservice.helper.UserHelper;
import com.corner.presenter.ILoginPresenter;
import com.corner.presenter.base.BasePresenter;
import com.corner.ui.view.ILoginView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by WeiHey on 2015/7/11，00.35.
 * 描述：登录presenter
 */
public class LoginPresenter extends BasePresenter<ILoginView> implements ILoginPresenter {
    @Override
    public void login(String phoneNum, String password) {
        UserHelper.login(phoneNum, password).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<User>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                if (view != null) {
                    view.loginError(e.getMessage());
                    view.showLoading(false);
                }
            }

            @Override
            public void onNext(User user) {
                if (view != null) {
                    view.loginSucess(user);
                    view.showLoading(false);
                }
            }

            @Override
            public void onStart() {
                if (view != null)
                    view.showLoading(true);
            }
        });
    }
}
